package com.hgnu.dorm.service.impl;

import com.hgnu.dorm.domain.dto.BuildingPageQueryDto;
import com.hgnu.dorm.domain.po.Building;
import com.hgnu.dorm.domain.po.PageBean;
import com.hgnu.dorm.mapper.BuildingMapper;
import com.hgnu.dorm.service.BuildingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BulidingServiceImpl implements BuildingService {

    @Autowired
    private BuildingMapper buildingMapper;
    @Override
    public PageBean page(BuildingPageQueryDto dto) {
        Long total = buildingMapper.count(dto);
        if(dto.getPage()<=0){
            dto.setPage(1);
        }
        if(dto.getPageSize()<=0){
            dto.setPageSize(10);
        }
        Integer start = (dto.getPage() - 1) * dto.getPageSize();
        dto.setStart(start);
        List<Building> page = buildingMapper.page(dto);
        return new PageBean(total, page);
    }

    @Override
    public void insertBuilding(Building building) {
        buildingMapper.insertBuilding(building);
    }

    @Override
    public void updateBuilding(Building building) {
        buildingMapper.updateBuilding(building);
    }

    @Override
    public void deleteBuilding(Long[] ids) {
        buildingMapper.deleteBuildingByIds(ids);
    }

    @Override
    public Building getById(Integer id) {
        if(id!=null){
            return buildingMapper.getById(id);
        }
        return null;
    }
}
